using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace MicroMsg.UI.Page
{
	public class ModifyAliasPage : BasePage
	{
		private EventWatcher m_ModifyAliasOK;
		private EventWatcher m_ModifyAliasErr;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal Grid ContentPanel;
		internal TextBlock txtBindedQQ;
		internal PhoneTextBox inputAlias;
		private bool _contentLoaded;
		public ModifyAliasPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.initData));
		}
		private void initData(object sender, RoutedEventArgs e)
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.m_ModifyAliasOK = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventModifyAliasOK));
			this.m_ModifyAliasErr = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventModifyAliasErr));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_GENERAL_SET_TYPE_SUCCESS, this.m_ModifyAliasOK);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_GENERAL_SET_TYPE_ERR, this.m_ModifyAliasErr);
			this.inputAlias.add_TextChanged(new TextChangedEventHandler(this.input_TextChanged));
			base.set_ApplicationBar(this.GetApplicationBar());
		}
		private void input_TextChanged(object sender, TextChangedEventArgs e)
		{
			string text = this.inputAlias.get_Text();
			if (text != null && text.get_Length() > 0)
			{
				base.get_ApplicationBar().set_IsMenuEnabled(true);
				return;
			}
			base.get_ApplicationBar().set_IsMenuEnabled(false);
		}
		protected override void OnPageOut()
		{
			if (this.m_ModifyAliasOK == null)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_GENERAL_SET_TYPE_SUCCESS, this.m_ModifyAliasOK);
			this.m_ModifyAliasOK = null;
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_GENERAL_SET_TYPE_ERR, this.m_ModifyAliasErr);
			this.m_ModifyAliasErr = null;
		}
		private void onEventModifyAliasOK(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.hideProgressCover();
			MessageBoxManager.ShowToast(strings.Set_Alias_Success, 2500, null, false);
			AccountMgr.getCurAccount().strAlias = this.inputAlias.get_Text();
			base.GoBack();
		}
		private void onEventModifyAliasErr(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.hideProgressCover();
			NetSceneGeneralSetResult netSceneGeneralSetResult = evtArgs.mObject as NetSceneGeneralSetResult;
			if (netSceneGeneralSetResult != null && netSceneGeneralSetResult.retCode == RetConst.MM_ERR_USEREXIST)
			{
				MMMessageBox.Show(strings.Set_Alias_ExistContent, true, "确定");
				return;
			}
			MessageBoxManager.ShowToast(strings.Set_Alias_Faild, 2500, null, false);
		}
		private void saveButton_Click(object sender, EventArgs e)
		{
			if (!ToolFunction.checkIsLegalNickName(this.inputAlias.get_Text()))
			{
				MMMessageBox.Show(strings.Set_Alias_Invalidate, true, "确定");
				return;
			}
			string string_ = string.Format(strings.Set_Alias_Confirm, this.inputAlias.get_Text());
			MMMessageBox mMMessageBox = MMMessageBox.Show("", string_, true, strings.COM_Confirm, strings.COM_Cancel);
			mMMessageBox.set_FontSize(22.0);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.MsgBoxSaveHandler);
		}
		public void MsgBoxSaveHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.showProgressCover(strings.Set_Alias_Modifying);
				ServiceCenter.sceneGeneralSet.doScene(GENERAL_SET_TYPE.GENERAL_SET_TYPE_ALIAS, this.inputAlias.get_Text());
				break;
			case 1:
				break;
			default:
				return;
			}
		}
		private void inputTxt_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.get_Key() == 3)
			{
				base.Focus();
			}
		}
		private void txtGotFofus(object sender, RoutedEventArgs e)
		{
			PhoneTextBox phoneTextBox = sender as PhoneTextBox;
			phoneTextBox.set_BorderBrush(R.theme.COMMON_BRUSH);
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, (SolidColorBrush)Application.get_Current().get_Resources().get_Item("HalfOpacityBrush1"), false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		public IApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/ico_save.png", 2));
			applicationBarIconButton.set_Text(strings.COM_Save);
			applicationBarIconButton.add_Click(new EventHandler(this.saveButton_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			return this.mBar;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/ModifyAliasPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.txtBindedQQ = (TextBlock)base.FindName("txtBindedQQ");
			this.inputAlias = (PhoneTextBox)base.FindName("inputAlias");
		}
	}
}
